package com.hzy.fivepalace.wx.controller.api;

import com.hzy.fivepalace.db.domain.DtsAddress;
import com.hzy.fivepalace.wx.annotation.LoginUser;
import com.hzy.fivepalace.wx.controller.base.BaseController;
import com.hzy.fivepalace.wx.service.WxAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 用户收货地址服务
 */
@RestController
@RequestMapping("/wx/address")
@Validated
@Api(tags = "用户收货地址服务")
public class WxAddressController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(WxAddressController.class);

    @Autowired
    private WxAddressService addressService;



    /**
     * 用户收货地址列表
     * @param userId
     * @param queryType
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "用户收货地址列表")
    public Object list(@LoginUser @ApiParam(hidden = true) Integer userId,
                       @ApiParam(value = "查询类型:0或空查全部,1只查默认地址") @RequestParam(value = "queryType", required = false) Integer queryType) {
        return addressService.list(userId,queryType);
    }

    /**
     * 收货地址详情
     *
     * @param userId 用户ID
     * @param id     收货地址ID
     * @return 收货地址详情
     */
    @GetMapping("/detail")
    @ApiOperation(value = "收货地址详情")
    public Object detail(@LoginUser @ApiParam(hidden = true) Integer userId, @ApiParam(value = "收货地址id") @NotNull Integer id) {

        return addressService.detail(userId, id);

    }


    /**
     * 添加或更新收货地址
     *
     * @param userId  用户ID
     * @param address 用户收货地址
     * @return 添加或更新操作结果
     */
    @PostMapping("/saveOrUpd")
    @ApiOperation(value = "添加或更新收货地址")
    public Object save(@LoginUser @ApiParam(hidden = true) Integer userId, @RequestBody DtsAddress address) {

        return addressService.saveOrUpd(userId, address);
    }


    /**
     * 删除收货地址
     *
     * @param userId
     * @param id
     * @return
     */
    @PostMapping("/delete")
    public Object delete(@LoginUser @ApiParam(hidden = true) Integer userId, @ApiParam(value = "收货地址id") @NotNull Integer id) {
        return addressService.delete(userId, id);
    }
}
